package com.hongkzh.www.adv.service;

import com.hongkzh.www.conmon.BigNumberFormat;
import com.hongkzh.www.conmon.RedisTool;
import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Record;

public class BaseService {
    public void doCache(Record r) {
        if (null == r) {
            return;
        }
        /**
         * 性别
         */
        if (StrKit.notBlank(r.getStr("sex"))) {
            String sexName = RedisTool.hgetDict("sex:" + r.get("sex"));
            r.set("sexName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("sexName", sexName);
            }
        }
        /**
         * 学历
         */
        if (StrKit.notBlank(r.getStr("education"))) {
            String sexName = RedisTool.hgetDict("hk_recruit_education:" + r.get("education"));
            r.set("educationName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("educationName", sexName);
            }

        }
        /**
         * 年限
         */
        if (StrKit.notBlank(r.getStr("workingLife"))) {
            String sexName = RedisTool.hgetDict("hk_recruit_workingLife:" + r.get("workingLife"));
            r.set("workingLifeName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("workingLifeName", sexName);
            }

        }

        if (StrKit.notBlank(r.getStr("constellation"))) {
            String sexName = RedisTool.hgetDict("hk_user_constellation:" + r.get("constellation"));
            r.set("constellationName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("constellationName", sexName);
            }

        }
        if (StrKit.notBlank(r.getStr("marital"))) {
            String sexName = RedisTool.hgetDict("hk_user_marital:" + r.get("marital"));
            r.set("maritalName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("maritalName", sexName);
            }

        }
        /**
         * 地点
         */
        if (StrKit.notBlank(r.getStr("located"))) {
            String sexName = RedisTool.hgetArea(r.get("located"));
            r.set("locatedName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("locatedName", sexName);
            }
        }
        /**
         *
         */
        if (StrKit.notBlank(r.getStr("functions"))) {
            String sexName = RedisTool.hgetRecruitCategory(r.get("functions"));
            r.set("functionsName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("functionsName", sexName);
            }


        }
        /**
         *
         */
        if (StrKit.notBlank(r.getStr("state"))) {
            String sexName = RedisTool.hgetDict("hk_recruit_state:" + r.get("state"));
            r.set("stateName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("stateName", sexName);
            }

        }
        /**
         *
         */
        if (StrKit.notBlank(r.getStr("workNature"))) {
            String sexName = RedisTool.hgetDict("hk_recruit_nature:" + r.get("workNature"));
            r.set("workNatureName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("workNatureName", sexName);
            }
        }
        /**
         *
         */
        if (StrKit.notBlank(r.getStr("nature"))) {
            String sexName = RedisTool.hgetDict("hk_recruit_nature:" + r.get("nature"));
            r.set("natureName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("natureName", sexName);
            }
        }
        /**
         * 地点
         */
        if (StrKit.notBlank(r.getStr("place"))) {
            String sexName = RedisTool.hgetArea(r.get("place"));
            r.set("placeName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("placeName", sexName);
            }
        }
        /**
         *   薪水
         */
        if (StrKit.notBlank(r.getStr("salary"))) {
            String sexName = RedisTool.hgetDict("hk_recruit_salary:" + r.get("salary"));
            r.set("salaryName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("salaryName", sexName);
            }
        }
        /**
         *   年龄
         */
        if (StrKit.notBlank(r.getStr("age"))) {
            String sexName = RedisTool.hgetDict("hk_recruit_age:" + r.get("age"));
            r.set("ageName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("ageName", sexName);
            }
        }

        /**
         *   月收入（薪水）
         */
        if (StrKit.notBlank(r.getStr("monthlyIncome"))) {
            String sexName = RedisTool.hgetDict("hk_recruit_salary:" + r.get("monthlyIncome"));
            r.set("monthlyIncomeName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("monthlyIncomeName", sexName);
            }
        }
        /**
         *
         */
        if (StrKit.notBlank(r.getStr("timeToPost"))) {
            String sexName = RedisTool.hgetDict("hk_recruit_timeToPost:" + r.get("timeToPost"));
            r.set("timeToPostName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("timeToPostName", sexName);
            }
        }
        /**
         * 发展阶段
         */
        if (StrKit.notBlank(r.getStr("stage"))) {
            String sexName = RedisTool.hgetDict("hk_recruit_stage:" + r.get("stage"));
            r.set("stageName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("stageName", sexName);
            }
        }
        /**
         * 公司规模
         */
        if (StrKit.notBlank(r.getStr("scale"))) {
            String sexName = RedisTool.hgetDict("hk_recruit_scale:" + r.get("scale"));
            r.set("scaleName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("scaleName", sexName);
            }
        }
        /**
         * 工作经验
         */
        if (StrKit.notBlank(r.getStr("experience"))) {
            String sexName = RedisTool.hgetDict("hk_recruit_experience:" + r.get("experience"));
            r.set("experienceName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("experienceName", sexName);
            }
        }
        if (StrKit.notBlank(r.getStr("areaId"))) {
            String sexName = RedisTool.hgetArea(r.get("areaId"));
            r.set("areaName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("areaName", sexName);
            }
        }
        if (StrKit.notBlank(r.getStr("industry"))) {
            String sexName = RedisTool.hgetRecruitIndustry(r.get("industry"));
            r.set("industryName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("industryName", sexName);
            }
        }
        if (StrKit.notBlank(r.getStr("category"))) {
            String sexName = RedisTool.hgetRecruitCategory(r.get("category"));
            r.set("categoryName", "");
            if (StrKit.notBlank(sexName)) {
                r.set("categoryName", sexName);
            }
        }
    }

    public void phone(Record r) {
        if (null == r) {
            return;
        }
        String phone = r.getStr("phone");
        phone = phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
        r.set("phone", phone);
    }

    //生成很多个*号
    public String createAsterisk(int length) {
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < length; i++) {
            stringBuffer.append("*");
        }
        return stringBuffer.toString();
    }

    public void doName(Record r) {
        if (null == r) {
            return;
        }
        String uName = r.getStr("uName");
        //uName= uName.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");

        if (uName.length() > 1) {
            uName = uName.replaceAll("([\\u4e00-\\u9fa5]{1})(.*)", "$1" + createAsterisk(uName.length() - 1));
        }

        r.set("uName", uName);
    }

    public void doShopPath(Record r) {
        if (null == r) {
            return;
        }
        String imgSrc = r.getStr("imgSrc");
        if (StrKit.notBlank(imgSrc) && imgSrc.indexOf("http") < 0) {

            r.set("imgSrc", PropKit.get("fileServer") + imgSrc);
        }
    }

    public void doImgPath(Record r) {
        if (null == r) {
            return;
        }
        String imgSrc = r.getStr("imgSrc");
        String coverImgSrc = r.getStr("coverImgSrc");
        String headImg = r.getStr("headImg");
        String rheadImg = r.getStr("rheadImg");
        String background = r.getStr("background");
        String portrait = r.getStr("portrait");

        String officialCoverImgSrc = r.getStr("officialCoverImgSrc");
        String traditionalCoverImgSrc = r.getStr("traditionalCoverImgSrc");
        String banner = r.getStr("banner");
        if (StrKit.notBlank(banner) && banner.indexOf("http") < 0) {

            r.set("banner", PropKit.get("fileServer") + banner);
        }
        if (StrKit.notBlank(portrait) && portrait.indexOf("http") < 0) {

            r.set("portrait", PropKit.get("fileServer") + portrait);
        }

        if (StrKit.notBlank(officialCoverImgSrc) && officialCoverImgSrc.indexOf("http") < 0) {

            r.set("officialCoverImgSrc", PropKit.get("fileServer") + officialCoverImgSrc);
        }
        if (StrKit.notBlank(traditionalCoverImgSrc) && traditionalCoverImgSrc.indexOf("http") < 0) {

            r.set("traditionalCoverImgSrc", PropKit.get("fileServer") + traditionalCoverImgSrc);
        }


        if (StrKit.notBlank(imgSrc) && imgSrc.indexOf("http") < 0) {

            r.set("imgSrc", PropKit.get("fileServer") + imgSrc);
        }
        if (StrKit.notBlank(coverImgSrc) && coverImgSrc.indexOf("http") < 0) {
            r.set("coverImgSrc", PropKit.get("fileServer") + coverImgSrc);
        }
        if (StrKit.notBlank(headImg) && headImg.indexOf("http") < 0) {
            r.set("headImg", PropKit.get("fileServer") + headImg);
        }
        if (StrKit.notBlank(rheadImg) && rheadImg.indexOf("http") < 0) {
            r.set("rheadImg", PropKit.get("fileServer") + rheadImg);
        }
        if (StrKit.notBlank(background) && background.indexOf("http") < 0) {
            r.set("background", PropKit.get("fileServer") + background);
        }
        String idCardImg = r.getStr("idCardImg");

        if (StrKit.notBlank(idCardImg) && idCardImg.indexOf("http") < 0) {

            r.set("idCardImg", PropKit.get("fileServer") + idCardImg);
        }
        String businessLicense = r.getStr("businessLicense");

        if (StrKit.notBlank(businessLicense) && businessLicense.indexOf("http") < 0) {

            r.set("businessLicense", PropKit.get("fileServer") + businessLicense);
        }

    }


    public void doPayType(Record r) {
        /**
         * 支付类型
         */
        /*if (StrKit.notBlank(r.getStr("payType"))) {
            String sexName = RedisTool.hgetDict("hk_shop_payType:" + r.get("payType"));
            r.set("payType", "");
            if (StrKit.notBlank(sexName)) {
                r.set("payType", sexName);
            }

        }*/
    }


    public String imgPath(String path) {
        return PropKit.get("fileServer") + path;
    }

    public void doNumberPath(Record r) {
        if (null == r) {
            return;
        }


        String playCount = r.getStr("playCount");
        if (playCount != null) {
            r.set("playCount", BigNumberFormat.dataFormat(Integer.parseInt(playCount)));
        }
        String shareCount = r.getStr("shareCount");
        if (shareCount != null) {
            r.set("shareCount", BigNumberFormat.dataFormat(Integer.parseInt(shareCount)));
        }

        String praiseCount = r.getStr("praiseCount");
        if (praiseCount != null) {
            r.set("praiseCount", BigNumberFormat.dataFormat(Integer.parseInt(praiseCount)));
        }

        String follows = r.getStr("follows");
        if (follows != null) {
            r.set("follows", BigNumberFormat.dataFormat(Integer.parseInt(follows)));
        }

        String circle = r.getStr("circle");
        if (circle != null) {
            r.set("circle", BigNumberFormat.dataFormat(Integer.parseInt(circle)));
        }
        String rewardCount = r.getStr("rewardCount");
        if (rewardCount != null) {
            r.set("rewardCount", BigNumberFormat.dataFormat(Integer.parseInt(rewardCount)));
        }

        String commentCount = r.getStr("commentCount");
        if (commentCount != null) {
            r.set("commentCount", BigNumberFormat.dataFormat(Integer.parseInt(commentCount)));
        }

        String collectionCount = r.getStr("collectionCount");
        if (collectionCount != null) {
            r.set("collectionCount", BigNumberFormat.dataFormat(Integer.parseInt(collectionCount)));
        }
        String userCount = r.getStr("userCount");
        if (userCount != null) {
            r.set("userCount", BigNumberFormat.dataFormat(Integer.parseInt(userCount)));
        }
        String people = r.getStr("people");
        if (people != null) {
            r.set("people", BigNumberFormat.dataFormatTenThousand(Integer.parseInt(people)));
        }


    }

    public void doFilePath(Record r) {
        if (null == r) {
            return;
        }
        String imgSrc = r.getStr("imgSrc");
        String coverImgSrc = r.getStr("coverImgSrc");
        String headImg = r.getStr("headImg");
        String rheadImg = r.getStr("rheadImg");
        String background = r.getStr("background");

        String officiaImgSrc = r.getStr("officiaImgSrc");
        if (StrKit.notBlank(officiaImgSrc) && officiaImgSrc.indexOf("http") < 0) {
            r.set("officiaImgSrc", PropKit.get("fileServer") + officiaImgSrc);
        }

        if (StrKit.notBlank(imgSrc) && imgSrc.indexOf("http") < 0) {
            r.set("imgSrc", PropKit.get("fileServer") + imgSrc);
        }
        if (StrKit.notBlank(coverImgSrc) && coverImgSrc.indexOf("http") < 0) {
            r.set("coverImgSrc", PropKit.get("fileServer") + coverImgSrc);
        }
        if (StrKit.notBlank(headImg) && headImg.indexOf("http") < 0) {
            r.set("headImg", PropKit.get("fileServer") + headImg);
        }
        if (StrKit.notBlank(rheadImg) && rheadImg.indexOf("http") < 0) {
            r.set("rheadImg", PropKit.get("fileServer") + rheadImg);
        }
        if (StrKit.notBlank(background) && background.indexOf("http") < 0) {
            r.set("background", PropKit.get("fileServer") + background);
        }


        Integer playCount = r.getInt("playCount");
        if (playCount != null) {
            r.set("playCount", BigNumberFormat.dataFormat(playCount));
        }
        Integer shareCount = r.getInt("shareCount");
        if (shareCount != null) {
            r.set("shareCount", BigNumberFormat.dataFormat(shareCount));
        }

        Integer praiseCount = r.getInt("praiseCount");
        if (praiseCount != null) {
            r.set("praiseCount", BigNumberFormat.dataFormat(praiseCount));
        }

        Integer follows = r.getInt("follows");
        if (follows != null) {
            r.set("follows", BigNumberFormat.dataFormat(follows));
        }

        Integer circle = r.getInt("circle");
        if (circle != null) {
            r.set("circle", BigNumberFormat.dataFormat(circle));
        }
        Integer rewardCount = r.getInt("rewardCount");
        if (rewardCount != null) {
            r.set("rewardCount", BigNumberFormat.dataFormat(rewardCount));
        }

        Integer commentCount = r.getInt("commentCount");
        if (commentCount != null) {
            r.set("commentCount", BigNumberFormat.dataFormat(commentCount));
        }

        Integer collectionCount = r.getInt("collectionCount");
        if (collectionCount != null) {
            r.set("collectionCount", BigNumberFormat.dataFormat(collectionCount));
        }
        Integer userCount = r.getInt("userCount");
        if (userCount != null) {
            r.set("userCount", BigNumberFormat.dataFormat(userCount));
        }
        Integer people = r.getInt("people");
        if (people != null) {
            r.set("people", BigNumberFormat.dataFormatTenThousand(people));
        }
    }


    public void doAccountPath(Record r) {
        if (null == r) {
            return;
        }
        String bankPositiveImg = r.getStr("bankPositiveImg");
        String bankBackImg = r.getStr("bankBackImg");
        String cardPositiveImg = r.getStr("cardPositiveImg");
        String cardBackImg = r.getStr("cardBackImg");
        if (StrKit.notBlank(bankPositiveImg) && bankPositiveImg.indexOf("http") < 0) {

            r.set("bankPositiveImg", PropKit.get("fileServer") + bankPositiveImg);
        }
        if (StrKit.notBlank(bankBackImg) && bankBackImg.indexOf("http") < 0) {

            r.set("bankBackImg", PropKit.get("fileServer") + bankBackImg);
        }
        if (StrKit.notBlank(cardPositiveImg) && cardPositiveImg.indexOf("http") < 0) {

            r.set("cardPositiveImg", PropKit.get("fileServer") + cardPositiveImg);
        }
        if (StrKit.notBlank(cardBackImg) && cardBackImg.indexOf("http") < 0) {

            r.set("cardBackImg", PropKit.get("fileServer") + cardBackImg);
        }
    }

}
